package client;

import com.zxp.*;

public class SubmitPanel extends javax.swing.JPanel {

    /** Creates new form SubmitPanel */
    public SubmitPanel(javax.swing.JDialog d) {
        initComponents();
        dialog = d;
        try {
            java.io.File dir = new java.io.File("./paper");
            String[] files = dir.list();
            for (int i = 0; i < files.length; i++) {
                java.io.File file = new java.io.File(dir, files[i]);
                JCB_Paper.addItem(file.getName());
            }
            JCB_Paper.setSelectedItem(Control.getPaperNo());
            pb = Control.getPaperBean();
            int papernum = pb.getProblemCount();
            for (int i = 0; i < papernum; i++) {
                JCB_Problem.addItem((char) ('A' + i) + ".   " + pb.getProblemAt(i).getTitle());
            }
            JCB_Problem.setSelectedIndex(Control.getNowpapernum());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        JCB_Paper = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        JCB_Problem = new javax.swing.JComboBox();
        JB_Submit = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jToolBar1.setRollover(true);

        jLabel1.setText("Paper:");
        jToolBar1.add(jLabel1);

        JCB_Paper.setEnabled(false);
        jToolBar1.add(JCB_Paper);

        jLabel2.setText("Problem:");
        jToolBar1.add(jLabel2);

        jToolBar1.add(JCB_Problem);

        JB_Submit.setText("Submit");
        JB_Submit.setFocusable(false);
        JB_Submit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        JB_Submit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        JB_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_SubmitActionPerformed(evt);
            }
        });
        jToolBar1.add(JB_Submit);

        add(jToolBar1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void JB_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_SubmitActionPerformed
        dialog.dispose();
        try {
            String temp = JCB_Paper.getSelectedItem().toString();
            temp = temp.substring(0, temp.length() - ".xml".length());
            RunSubmit runSubmit = new RunSubmit(temp, Integer.toString(JCB_Problem.getSelectedIndex()));
            Thread thread = new Thread(runSubmit);
            thread.start();
        } catch (Exception e) {
        }
}//GEN-LAST:event_JB_SubmitActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_Submit;
    private javax.swing.JComboBox JCB_Paper;
    private javax.swing.JComboBox JCB_Problem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

    private PaperBean pb;
    javax.swing.JDialog dialog;
}
